home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI672.ASC < prev    next >
Text File  |  1992-02-28  |  6KB  |  331 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Turbo Pascal                           NUMBER  :  672
  9.   VERSION  :  6.0
  10.        OS  :  MS/PC DOS
  11.      DATE  :  February 28, 1992                        PAGE  :  1/5
  12.  
  13.     TITLE  :  How to Create a Listbox and Get a Double Click
  14.  
  15.  
  16.  
  17.  
  18.   {
  19.  
  20.   The following example demonstrates how to create a listbox
  21.   of file items and enable the user to double click on any item.
  22.   This produces a Message Box containing the listbox selected
  23.   item.
  24.  
  25.   }
  26.   {$X+}
  27.   Program Simple_ListBox;
  28.  
  29.   Uses
  30.     Objects, Drivers, Views, Menus, Dialogs, App, Crt, Dos, MsgBox;
  31.  
  32.   Const
  33.    cmNewCollect = 102;
  34.  
  35.   Type
  36.  
  37.    TMyApp = object(TApplication)
  38.        Constructor Init;
  39.        Procedure Initstatusline; Virtual;
  40.        Procedure Initmenubar; Virtual;
  41.        Procedure NewCollect; Virtual;
  42.        Procedure HandleEvent(var Event: TEvent); Virtual;
  43.      End;
  44.  
  45.     PListBox = ^RListBox;
  46.     RListBox = object(TListBox)
  47.       Constructor Init(var Bounds:TRect; ANumCols:Word; AScrollBar:
  48.                            PScrollBar);
  49.       Procedure Process;
  50.       Destructor Done; Virtual;
  51.     End;
  52.  
  53.     PMyDialog = ^MyDialog;
  54.     MyDialog = object(TDialog)
  55.       Constructor Init(var Bounds: TRect; MyTitle:TTitleStr);
  56.       Destructor Done; Virtual;
  57.       Procedure HandleEvent(var Event: TEvent); Virtual;
  58.     End;
  59.  
  60.   Var
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Turbo Pascal                           NUMBER  :  672
  75.   VERSION  :  6.0
  76.        OS  :  MS/PC DOS
  77.      DATE  :  February 28, 1992                        PAGE  :  2/5
  78.  
  79.     TITLE  :  How to Create a Listbox and Get a Double Click
  80.  
  81.  
  82.  
  83.  
  84.     NameList: PStringCollection;
  85.     PList: ^Rlistbox;
  86.     MyApp: TMyApp;
  87.  
  88.   Constructor Mydialog.Init(var Bounds:TRect; MyTitle: TTitleStr);
  89.   Begin
  90.     TDialog.Init(Bounds, MyTitle);
  91.   End;
  92.  
  93.   Destructor Mydialog.Done;
  94.   Begin
  95.     TDialog.Done;
  96.     Dispose(NameList, Done);
  97.   End;
  98.  
  99.   Procedure MyDialog.HandleEvent(var Event:TEvent);
  100.   var
  101.     Index: integer;
  102.   Begin
  103.     TDialog.HandleEvent(Event);
  104.     if (Event.Double = true) and (Event.What = evNothing) then
  105.       begin
  106.         sound(100);
  107.         delay(100);
  108.         nosound;
  109.         Index:=(PList^.Focused);
  110.         Messagebox(PList^.GetText(Index,20) ,nil, mfOkButton);
  111.       end;
  112.     ClearEvent(Event);
  113.   End;
  114.  
  115.   Constructor TMyApp.Init;
  116.   Begin
  117.     TApplication.Init;
  118.   End;
  119.  
  120.   Constructor RListBox.Init(var Bounds:TRect; ANumCols:Word;
  121.   AScrollBar:
  122.                             PScrollBar);
  123.   Begin
  124.     TListBox.Init(Bounds, ANumCols, AScrollBar);
  125.   End;
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Turbo Pascal                           NUMBER  :  672
  141.   VERSION  :  6.0
  142.        OS  :  MS/PC DOS
  143.      DATE  :  February 28, 1992                        PAGE  :  3/5
  144.  
  145.     TITLE  :  How to Create a Listbox and Get a Double Click
  146.  
  147.  
  148.  
  149.  
  150.   Destructor RListBox.Done;
  151.   Begin
  152.     TListBox.Done;
  153.   End;
  154.  
  155.   Procedure TMyApp.InitStatusLine;
  156.   Var
  157.     R:TRect;
  158.   Begin
  159.     GetExtent(R);
  160.     R.A.Y := R.B.Y -1;
  161.     Statusline :=new(PStatusLine, init(R,
  162.     NewStatusDef(0,$FFFF,
  163.     NewStatusKey('~Alt-X~ Exit',kbAltX, cmQuit,
  164.     NewStatusKey('~F10~ Menu',kbF10,cmMenu,
  165.     Nil)),Nil)
  166.     ));
  167.   End;
  168.  
  169.   Procedure RListBox.Process;
  170.   var
  171.     DirInfo: SearchRec;
  172.   Begin
  173.     NameList:=New(PStringCollection, Init(50,10));
  174.     With NameList^ do
  175.     Begin
  176.       FindFirst('*.*', Archive, DirInfo);
  177.       while DosError = 0 do
  178.         Begin
  179.           Insert(Newstr(Dirinfo.Name));
  180.           FindNext(DirInfo);
  181.         End;
  182.     End;
  183.   End;
  184.  
  185.   Procedure TMyApp.NewCollect;
  186.   Var
  187.     MyBox: PMyDialog;
  188.     R: TRect;
  189.     PBorland: ^TScrollBar;
  190.     Col: word;
  191.   Begin
  192.     Plist^.Process;
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Turbo Pascal                           NUMBER  :  672
  207.   VERSION  :  6.0
  208.        OS  :  MS/PC DOS
  209.      DATE  :  February 28, 1992                        PAGE  :  4/5
  210.  
  211.     TITLE  :  How to Create a Listbox and Get a Double Click
  212.  
  213.  
  214.  
  215.  
  216.     R.Assign(10,10,60,20);
  217.     MyBox := New(PMyDialog, Init(R, 'Scroll Collection'));
  218.     Col:=1;
  219.     R.Assign(40, 1, 41, 9);
  220.     PBorland:= New(PScrollBar, Init(R));
  221.     R.Assign(9, 1, 40, 9);
  222.     Plist:=New(PListbox, Init(R,Col,PBorland));
  223.     Plist^.Newlist(Namelist);
  224.     MyBox^.Insert(PBorland);
  225.     MyBox^.Insert(PList);
  226.     Desktop^.Insert(MyBox);
  227.   End;
  228.  
  229.   Procedure TMyApp.HandleEvent(var Event: TEvent);
  230.   Begin
  231.     TApplication.HandleEvent(Event);
  232.     if Event.What = evCommand then
  233.       Begin
  234.         case Event.Command of
  235.           cmNewCollect: Newcollect;
  236.         else
  237.           ClearEvent(Event);
  238.           Exit;
  239.         End;
  240.         ClearEvent(Event);
  241.       End;
  242.   End;
  243.  
  244.   Procedure TMyApp.InitMenubar;
  245.   var
  246.     R: TRect;
  247.   Begin
  248.     GetExtent(R);
  249.     R.B.Y := R.A.Y +1;
  250.     MenuBar :=new(PMenubar, Init(R, Newmenu(
  251.     NewSubMenu('~L~istbox Menu', hcNoContext, Newmenu(
  252.     NewItem('~B~ox','',kbF9, cmnewcollect, hcnocontext,
  253.     NewLine(
  254.     NewItem('~E~xit','', kbf10, cmquit, hcnocontext,
  255.     Nil)))), Nil))));
  256.   End;
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Turbo Pascal                           NUMBER  :  672
  273.   VERSION  :  6.0
  274.        OS  :  MS/PC DOS
  275.      DATE  :  February 28, 1992                        PAGE  :  5/5
  276.  
  277.     TITLE  :  How to Create a Listbox and Get a Double Click
  278.  
  279.  
  280.  
  281.  
  282.   Begin
  283.     MyApp.Init;
  284.     MyApp.Run;
  285.     MyApp.Done;
  286.   End.
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.